package com.oner365.test.function;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.oner365.test.enums.AchievementMapEnum;
import com.oner365.test.enums.TypeMapEnum;

public class MapFunction {
  private static final Logger LOGGER = LoggerFactory.getLogger(MapFunction.class);
  static Map<String, Function<Integer,String>> typeMap = new HashMap<>();
  static Map<String, Function<ParamClass,String>> achievementMap = new HashMap<>();
  public static void main(String[] args) {
    LOGGER.info("获取数据:{}",typeMap.get(TypeMapEnum.BEER.name()).apply(10));
    LOGGER.info("获取数据:{}",typeMap.get(TypeMapEnum.FOOD.name()).apply(2));
    LOGGER.info("获取数据:{}",typeMap.get(TypeMapEnum.TEA.name()).apply(1));
    LOGGER.info("获取数据:{}",achievementMap.get(AchievementMapEnum.CHINESE.name()).apply(new ParamClass("LT",100)));
    LOGGER.info("获取数据:{}",achievementMap.get(AchievementMapEnum.ENGLISH.name()).apply(new ParamClass("LT",99)));
    LOGGER.info("获取数据:{}",achievementMap.get(AchievementMapEnum.MATH.name()).apply(new ParamClass("LT",90)));

  }
  
  static {
    typeMap.put(TypeMapEnum.TEA.name(), count -> getTea(count));
    typeMap.put(TypeMapEnum.FOOD.name(), count -> getFood(count));
    typeMap.put(TypeMapEnum.BEER.name(), count -> getBeer(count));
    achievementMap.put(AchievementMapEnum.CHINESE.name(), paramClass -> getChinese(paramClass));
    achievementMap.put(AchievementMapEnum.ENGLISH.name(), paramClass -> getEnglish(paramClass));
    achievementMap.put(AchievementMapEnum.MATH.name(), paramClass -> getMath(paramClass));
  }
  
  public static String getTea(Integer count) {
    return "得到"+count+"杯茶水";
  }
  
  public static String getFood(Integer count) {
    return "得到"+count+"份食物";
  }
  
  public static String getBeer(Integer count) {
    return "得到"+count+"杯啤酒";
  }
  
  public static String getChinese(ParamClass paramClass) {
    return paramClass.getName()+"语文得到"+paramClass.getAchievement()+"分";
  }
  
  public static String getEnglish(ParamClass paramClass) {
    return paramClass.getName()+"英语得到"+paramClass.getAchievement()+"分";
  }
  
  public static String getMath(ParamClass paramClass) {
    return paramClass.getName()+"数学得到"+paramClass.getAchievement()+"分";
  }
  
  public static class ParamClass{
    String name;
    
    Integer achievement;
    
    ParamClass(){
      
    }
    
    ParamClass(String name,Integer achievement){
      this.name = name;
      this.achievement = achievement;
    }

    /**
     * @return the name
     */
    public String getName() {
      return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
      this.name = name;
    }

    /**
     * @return the achievement
     */
    public Integer getAchievement() {
      return achievement;
    }

    /**
     * @param achievement the achievement to set
     */
    public void setAchievement(Integer achievement) {
      this.achievement = achievement;
    }
    
    
    
  }
}


